package jdbc;

import jdbc.common.InputUtil;
import java.sql.Connection;
import java.sql.Statement;


public class RegUserDemo {
    public static void main(String[] args) throws Exception {
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo(), "欢迎注册");

        Connection connection = DBUtil.getConnection();

        Statement statement = connection.createStatement();

        String sql = "INSERT INTO userinfo(username,password,nickname,age) " +
                "VALUES('" + userInfo.getUsername() +
                "','" + userInfo.getPassword() +
                "','" + userInfo.getNickname() +
                "'," + userInfo.getAge() + ")";

        int count = statement.executeUpdate(sql);
        System.out.println(count > 0 ? "注册成功" : "注册失败");
        statement.close();
    }
}
